Skip to content

Fix #991: Add input validation and improve error handling in CartActionBean#1052

Merged
hazendaz merged 1 commit intomybatis:masterfrom
JongMinCh0i:fix/cart-safety-improvements-991
Jan 25, 2026
Merged

Fix #991: Add input validation and improve error handling in CartActionBean#1052
hazendaz merged 1 commit intomybatis:masterfrom
JongMinCh0i:fix/cart-safety-improvements-991

Conversation

@JongMinCh0i
Copy link
Contributor

Description:

This PR addresses the safety concerns raised in issue #991. I've added validation to prevent NPEs when workingItemId is null or blank, and made the exception handling more specific.

What changed:

I added null/blank checks at the beginning of addItemToCart() and removeItemFromCart() methods. When invalid input is detected, the methods now return early with an error message instead of crashing later. I also changed the catch block in updateCartQuantities() from catching generic Exception to specifically catching NumberFormatException, which is what we actually expect when parsing fails.

Tests:

Added a comprehensive test suite (CartActionBeanTest) that covers:

Null, empty, and blank workingItemId scenarios for both add and remove operations
Attempting to remove items that don't exist in the cart
Basic cart operations like clearing
All unit tests pass. The integration tests (ScreenTransitionIT) fail, but that's because they need a running server - not related to these changes.

Related:

Fixes #991

- Add null/blank validation for workingItemId in addItemToCart()
- Add null/blank validation for workingItemId in removeItemFromCart()
- Narrow exception handling in updateCartQuantities() to NumberFormatException
- Add comprehensive unit tests with ActionBeanContext mocking

This addresses the safety concerns raised in issue mybatis#991 by adding
early validation checks and replacing overly broad exception handling
with specific exception types.
@coveralls
Copy link

Coverage Status

coverage: 72.006% (+3.2%) from 68.791%
when pulling 5a81f2f on JongMinCh0i:fix/cart-safety-improvements-991
into 4ea1856 on mybatis:master.

@hazendaz hazendaz merged commit 7d3da1e into mybatis:master Jan 25, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FIX] Improve safety in CartActionBean: null workingItemId check + narrow exception handling

3 participants